<?php
class Mypage extends CI_Controller {
public static function get_instance() {
		
	}

	function index() {
		if($this->session->userdata('is_logged_in'))
		{ 
			//由于php中默认的是格林尼治时区，修改为东八区
			date_default_timezone_set('Asia/Chongqing');
			
			$this->load->model('user_model');
			$this->load->model('city_model');
			$this->load->model('calendar_model');
			
			//获取用户的未来日程
			$cal_future=$this->calendar_model->get_cal_by_time("today");
			
			//获取用户默认的城市
			$location_id=$this->user_model->get_user_city();
			$point=$this->city_model->get_city_point($location_id);
			
			$data=array(
			'location_x'=>$point['location_x'],
			'location_y'=>$point['location_y'],
			'cal_future_result'=>$cal_future,
			);
		
			$this->load->view('mypage/main',$data);
		}
		else 
			redirect(base_url());
	}
	
	function create_calender(){
		//插入数据
		if($this->session->userdata('is_logged_in'))
		{
			$this->load->model('calendar_model');
			$query = $this->calendar_model->create_calendar();

			if ($query){
				echo "添加日程成功！";
			}
			else{
				echo "你填写的时间格式不正确或重复，请重新选择！";
			}
		}
		else 
			include_once('index.html');
	}
}
